package 剑指offer.Month7_07.day16;

import java.util.ArrayList;

public class 二叉搜索树的第K个节点 {
    ArrayList<TreeNode> list = new ArrayList<>();
    public int KthNode (TreeNode proot, int k) {
        // write code here
        if(proot == null) return -1;
        solve(proot);
        if(list.size() < k || k <= 0) return -1;
        return list.get(k - 1).val;
    }

    public void solve(TreeNode proot) {
        // write code here
        if(proot == null) return;

        solve(proot.left);
        list.add(proot);
        solve(proot.right);
    }
}
